package com.itheima3.controller;

import com.itheima3.domain.User;
import com.itheima3.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService service;
    // 请求地址  http://localhost:8080/user/quick
    @RequestMapping("/helloooo")
    public String save(){
        System.out.println("Controller save running....");
        // 如果是重定向  "redirect:/jsp/success.jsp";
        // 如果是转发    "forward:/jsp/success.jsp";
        return "success";
    }
    @RequestMapping("/helltttt")
    public String save11(){
        System.out.println("Controller save running....");
        // 如果是重定向  "redirect:/jsp/success.jsp";
        // 如果是转发    "forward:/jsp/success.jsp";
        return "hello";
    }
    @RequestMapping("/regist")
    public String regist(User user){
        System.out.println("-----------------");
        System.out.println(user);
        service.regist(user);
        return  "forward:/jsp/success.jsp";
    }
    @RequestMapping("/test")
    @ResponseBody
    public String test(@RequestParam(value = "user",required = false ,defaultValue = "user") User user){
        System.out.println(user);
        /*service.regist(user);*/
        return  "张三";
    }
    @RequestMapping("/test2")
    @ResponseBody
    public String test2(String username, MultipartFile file1,MultipartFile file2){
        System.out.println(file1.getSize());
        /*service.regist(user);*/
        return  "张三";
    }
}
